import { message } from 'antd';
import { getStuffList,searchPosition,addStuff,updateStuff,deleteStuff, revalidateSysEmployee } from '../services'

export default {
    namespace: 'stuffManageModel',

    state: {
        stuffList: [],
        stuffTotal: 0,
    },

    effects: {
        *getStuffList({payload},{put,call}){
            const res= yield call(getStuffList, payload);
            const { code, data,  message: errMsg } = res;
            if(code === 0) {
                const {total,dataList} = data;
                yield put({
                    type: 'updateModel',
                    payload: {
                        stuffList: dataList,
                        stuffTotal: total,
                    }
                })
            }else{
              message.error(errMsg);
            }
        },

        *searchPosition({payload},{put, call, select}){
            return yield call(searchPosition,payload)
        },

        *addStuff({payload},{put, call, select}){
            return yield call(addStuff,payload)
        },

        *updateStuff({payload},{put, call, select}){
            return yield call(updateStuff,payload)
        },

        *deleteStuff({ payload }, { put, call, select }) {
            return yield call(deleteStuff, payload);
        },

        *revalidateSysEmployee({ payload }, { put, call, select }) {
            return yield call(revalidateSysEmployee, payload);
        },
    },

    reducers:{
        /* 更新状态（通用） */
        updateModel: (state, { payload }) => ({
        ...state,
        ...payload,
      }),
    }
}